<template>
  <a-modal v-bind:visible="isShowReal" title="实名" @ok="handleOk" @cancel="onCancel">
    <a-form-model :model="form" ref="formRef" :rules="formRule" :label-col="{ span: 5 }" :wrapper-col="{ span: 17 }">
      <a-form-model-item label="姓名" prop="realname">
        <a-input v-model="form.realname"></a-input>
      </a-form-model-item>
      <a-form-model-item label="身份证号" prop="id_card">
        <a-input v-model="form.id_card"></a-input>
      </a-form-model-item>
    </a-form-model>
  </a-modal>
</template>
<script>
import { changeGradeAPI } from '@/api/userinfo.js'
export default {
  name: 'ShowReal',
  props: {
    isShowReal: {
      type: Boolean,
      default: false
    },
    viewId: {
      type: Number,
      default: undefined
    }
  },
  data() {
    return {
      form: {
        brand_id: process.env.VUE_APP_BRAND_ID,
        id_card: '',
        ids: '',
        is_real_verify: '1',
        realname: ''
      },
      formRule: {
        realname: [{ required: true, message: '请输入姓名' }],
        id_card: [
          { required: true, message: '请输入身份证号', trigger: 'blur' },
          {
            pattern: /^[1-9]\d{5}(18|19|([23]\d))\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$/,
            message: '请输入正确身份证号',
            trigger: 'blur'
          }
        ]
      }
    }
  },
  methods: {
    handleOk() {
      this.$refs.formRef.validate(async valid => {
        if (!valid) return
        this.form.ids = this.viewId
        try {
          await changeGradeAPI(this.form)
          this.$emit('upload')
          this.$emit('update:isShowReal', false)
          this.$emit('update:viewId', undefined)
          this.$refs.formRef.resetFields()
          this.$message.success('操作成功')
        } catch (error) {
          this.$message.error(error.data.msg)
        }
      })
    },
    onCancel() {
      this.$emit('update:isShowReal', false)
      this.$emit('update:viewId', undefined)
      this.$refs.formRef.resetFields()
    }
  }
}
</script>

<style lang="less" scoped></style>
